package com.chenfeng.ego.controller;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chenfeng.ego.commons.pojo.EasyUIDataGrid;
import com.chenfeng.ego.commons.pojo.EgoResult;
import com.chenfeng.ego.pojo.TbItemParam;
import com.chenfeng.ego.service.TbItemParamService;
@Controller
public class TbItemParamController
{
	@Resource
	TbItemParamService itemParamService;
	// 参数列表的查询
	@RequestMapping("item/param/list")
	@ResponseBody
	public EasyUIDataGrid showParam(int page, int rows)
	{
		return this.itemParamService.selCatParam(page, rows);
	}
	//查询商品规格
	@RequestMapping("item/param/query/itemcatid/{catId}")
	@ResponseBody
	public EgoResult queryCatParam(@PathVariable Long catId)
	{
		EgoResult result = new EgoResult();
		/*int flag = this.itemParamService.selParamCat(catId);*/
		TbItemParam ta=this.itemParamService.showTbitemParam(catId);
		if (ta!=null)
		{
			//应该是最终的属性有就可以了
			result.setData(ta);
			result.setStatus(200);
		} else
		{
			result.setData(false);
			result.setStatus(400);
		}
		return result;
	}
	//参数的保存
	@RequestMapping("/item/param/save/{id}")
	@ResponseBody
	public EgoResult insertParamData(TbItemParam param,@PathVariable Long id)
	{
		EgoResult result = new EgoResult();	
		try
		{
			int flag = this.itemParamService.insertParent(param, id);
			if(flag>0)
			{
				result.setStatus(200);
			}else
			{
				result.setStatus(400);
			}
		} catch (Exception e)
		{
			e.printStackTrace();
			result.setStatus(400);
		}
		return result;
	}
	//参数的删除
	@RequestMapping("item/param/delete")
	@ResponseBody
	public EgoResult deleteParam(@RequestParam(name="ids") List<Long> ids)
	{
		
		EgoResult er = new EgoResult();
		try
		{
			int result = this.itemParamService.deleteByIds(ids);
			if(result>0)
			{
				er.setStatus(200);
			}
		} catch (Exception e)
		{
			er.setStatus(400);
			e.printStackTrace();
		}
		return er;
	}
}
